import argparse

# 同时出现位置参数和可选参数

parser = argparse.ArgumentParser()
parser.add_argument('square', type=int,
                    help='display a square of a given number')
parser.add_argument('-v', '--verbosity', type=int,
                    help='increase output verbosity')
args = parser.parse_args()
answer = args.square**2

# python argparse5.py #ERROR
# python argparse5.py 32
# python argparse5.py 32 -v 1
# python argparse5.py 32 -v 2
if args.verbosity == 2:
    print('The square of {} equals {}'.format(args.square, answer))
elif args.verbosity == 1:
    print('{}^2 == {}'.format(args.square, answer))
else:
    print(answer)
